/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.control.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.commands.SequenceCommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import multimedia.control.business.XMLDelegate;
	import multimedia.control.event.LoadViewerXMLEvent;
	import multimedia.model.ModelLocator;
	import multimedia.model.vo.SlideStepVO;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.IResponder;
    	
	/**
	 * 	LoadViewerXMLCommand
	 * 
	 *	@author jemden
	 *	@version 1.0
	 */
	public class LoadViewerXMLCommand extends SequenceCommand implements ICommand, IResponder
	{
		private var model:ModelLocator;
		
		private var e:LoadViewerXMLEvent;	
				
		override public function execute(event:CairngormEvent):void
		{
			this.model = ModelLocator.getInstance();
			this.e = event as LoadViewerXMLEvent;
			this.nextEvent = e.nextEvent;
			var service:XMLDelegate = new XMLDelegate(this);
			model.log = e.slide.url + "/data/viewer.xml";
			service.loadViewer(e.slide.url + "/data/viewer.xml");
		}
		
		public function result(data:Object):void
		{
			var slides:ArrayCollection;
			if(data.result["presentation"].slides.slide is ArrayCollection)
			{
				slides = data.result["presentation"].slides.slide;
			} else
			{
				slides = new ArrayCollection(new Array(data.result["presentation"].slides.slide));
			}
			
			var slide:Object;
			var slideStep:SlideStepVO;
			for each (slide in slides)
			{
				slideStep = new SlideStepVO();
				e.slide.slideSteps.addItem(new SlideStepVO());
			}
			executeNextCommand();
		}
		
		public function fault(info:Object):void
		{
			model.log += "LoadViewerXMLCommand Error";
		}
	}
}